package com.zrgj.vo;


import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;

public class Pinyin {
    public static String getFirstPinyin(String hanzi) throws BadHanyuPinyinOutputFormatCombination {
        HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
//        format.setCaseType(HanyuPinyinCaseType.UPPERCASE);//大写
        format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);//不标声调

        StringBuilder res=new StringBuilder();
        for ( char c: hanzi.toCharArray()){
            String[] pinyin= PinyinHelper.toHanyuPinyinStringArray(c,format);
            res.append(pinyin[0].charAt(0));
        }
        return res.toString();
    }


//        HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
//        format.setCaseType(HanyuPinyinCaseType.UPPERCASE);//大写
//        //format.setCaseType(HanyuPinyinCaseType.LOWERCASE);//小写
//        format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);//不标声调
//        //format.setToneType(HanyuPinyinToneType.WITH_TONE_MARK);//标符号声调放韵母上[LǙ]
//        //format.setToneType(HanyuPinyinToneType.WITH_TONE_NUMBER);//标数字声调放最右边[LÜ3]
//        format.setVCharType(HanyuPinyinVCharType.WITH_U_UNICODE);// u:的声母
//
//        //类似日期时间格式化
//        System.out.println(Arrays.toString(PinyinHelper.toHanyuPinyinStringArray('智', format)));
//        System.out.println(Arrays.toString(PinyinHelper.toHanyuPinyinStringArray('宇')));
//        //国语罗马字
//        System.out.println(Arrays.toString(PinyinHelper.toGwoyeuRomatzyhStringArray('智')));
//        //注音符号拼音
//        System.out.println(Arrays.toString(PinyinHelper.toMPS2PinyinStringArray('宇')));
//        //通用拼音
//        System.out.println(Arrays.toString(PinyinHelper.toTongyongPinyinStringArray('智')));
//        //威妥玛拼音
//        System.out.println(Arrays.toString(PinyinHelper.toWadeGilesPinyinStringArray('宇')));
//        //耶魯拼音
//        System.out.println(Arrays.toString(PinyinHelper.toYalePinyinStringArray('智')));


}
